package cn.zyx.controller;

import cn.zyx.entity.User;
import cn.zyx.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (User)后台登录
 *
 * @author makejava
 * @since 2021-12-11 18:49:59
 */
@RestController
@RequestMapping("user")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    /**
     * 登录
     * @param username
     * @param
     * @return
     */
    @PostMapping("login")
    public User Login(String username){
        return userService.Login(username);
    }

    /**
     * 添加登录用户
     * @param username
     * @param password
     * @return
     */
    @RequestMapping("add")
    public User add(String username,String password){
        User user=new User(null,username,password);
        return userService.insert(user);
    }

    /**
     * 通过id删除登录用户
     * @param id
     * @return
     */
    @RequestMapping("del")
    public boolean delete(Integer id){
        return userService.deleteById(id);
    }

    /**
     * 通过id修改登录用户
     * @param id
     * @param password
     * @return
     */
    @RequestMapping("upd")
    public User update(Integer id,String password){
        User user=new User();
        user.setId(id);
        user.setPassword(password);
        return userService.update(user);
    }


}